package com.college.controller.products;


import com.college.common.pojo.ao.Collection;
import com.college.common.pojo.dto.products.AddCollectionDTO;
import com.college.common.pojo.dto.products.QueryCollectionDTO;
import com.college.common.pojo.dto.products.UpdateCollectionDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonPage;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.products.service.CollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收藏 前端控制器
 * @author 小C工作室
 * @since 2025-02-22
 */
@RestController
@RequestMapping("/collection")
@Api(tags = "收藏")
@Slf4j
public class CollectionController {

    @Autowired
    private CollectionService collectionService;

    @ApiOperation(value = "查询收藏列表")
    @GetMapping(value = "/query-list")
    public CommonResult<List<Collection>> queryList(QueryCollectionDTO queryCollectionDTO) {
        return CommonResult.success(collectionService.queryList(queryCollectionDTO));
    }

    @ApiOperation(value = "查询收藏列表分页")
    @GetMapping(value = "/query-list-page")
    public CommonResult<CommonPage<Collection>> queryListPage(QueryCollectionDTO queryCollectionDTO , PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(collectionService.queryListPage(queryCollectionDTO,pageParamRequest)));
    }

    @ApiOperation(value = "新增收藏")
    @PostMapping(value = "/add")
    public CommonResult<String> addCollection(@RequestBody AddCollectionDTO addCollectionDTO) {
        return collectionService.addCollection(addCollectionDTO);
    }

    @ApiOperation(value = "删除收藏")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<Boolean> deleteCollection(@PathVariable Long id) {
        return CommonResult.success(collectionService.removeById(id));
    }

    @ApiOperation(value = "批量删除收藏")
    @DeleteMapping(value = "/batch-delete")
    public CommonResult<Boolean> deleteCollection(@RequestBody List<Long> ids) {
        if (ObjectUtil.isNotEmpty(ids)) {
            return CommonResult.success(collectionService.removeByIds(ids));
        }
        return CommonResult.success("参数错误");
    }

    @ApiOperation(value = "更新收藏")
    @PutMapping(value = "/update")
    public CommonResult<String> updateCollection(@RequestBody UpdateCollectionDTO updateCollectionDTO) {
        return collectionService.updateCollection(updateCollectionDTO);
    }
}

